package com.chanyachting.emall.action.recruitmentinformation;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.chanyachting.emall.domain.Joblist;
import com.chanyachting.emall.domain.Recruitmentinformation;
import com.chanyachting.emall.form.JoblistForm;
import com.chanyachting.emall.service.RecruitmentinformationService;
import com.chanyachting.emall.serviceImpl.RecruitmentinformationServiceImpl;
import com.chanyachting.emall.util.RequestUtil;

public class AddJobListAction extends Action {

	//添加招聘岗位
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		RequestUtil ru=new RequestUtil(request);
		
		int riId=Integer.parseInt(ru.getParameter("riId", "0"));
		
		
		JoblistForm jlform=(JoblistForm)form;
		
		Joblist job=new Joblist();
		
		BeanUtils.copyProperties(job, jlform);
		
		if(riId!=0){
			
			//如果有招聘信息编号，直接保存到数据库
			
			RecruitmentinformationService ris=new RecruitmentinformationServiceImpl();
			
			Recruitmentinformation ri=new Recruitmentinformation(riId);
			
			//ri=ris.getOneRecruitmentinformation(ri);
			
			ris.addJobList(ri, job);
		
			
		}else{
			
			//如果没有招聘信息对象编号,岗位信息先保存到session

			List jobList=(List)ru.getSessionObject(RecruitmentinformationService.JOBLLIST_IN_SESSION, new ArrayList());
		
			jobList.add(job);
			
			ru.setSessionObject(RecruitmentinformationService.JOBLLIST_IN_SESSION, jobList);

		}

		return mapping.findForward("");
	}
	
	

}
